package de.jonasjelten.jcalc.mathExps;

import de.jonasjelten.jcalc.exception.JEvaluationException;
import de.jonasjelten.jcalc.math.JNumber;
import de.jonasjelten.jcalc.math.JDualNumber;

/**
 * Diese Klasse beschreibt ein klassisches "hoch"
 * wobei (basis)^(exponent) gerechnet wird.
 * @author michael
 */
public class JPow extends JDualArgMathExp {

    public JPow(JMathExp base, JMathExp exponent) {
        super(base, exponent);
    }

    @Override
    public JNumber eval() throws JEvaluationException {
        JDualNumber childrenEvaluated = super.evalChildren();
        super.jcalc.expgroup.addActive();
        JNumber res = childrenEvaluated.getNumber0().pow(childrenEvaluated.getNumber1());
        super.jcalc.expgroup.setInactive();
        return res;
    }

    @Override
    public String toString() {
        return super.toString(true, "^");
    }

    @Override
    public boolean isTrivial() {
        return false;
    }
}
